package com.gzrhhscd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gzrhhscd.Pojo.Emp;
import com.gzrhhscd.Pojo.PageBean;
import com.gzrhhscd.mapper.EmpMapper;
import com.gzrhhscd.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
//    @Override
//    public PageBean Page(Integer page,Integer pageSize) {
//       long count= empMapper.count();
//       Integer start=(page-1)*pageSize;
//        List<Emp> empList=empMapper.Page(start,pageSize);
//        return new PageBean(count,empList);
//    }
@Override
public PageBean Page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin,LocalDate end) {
   //1.set the page and pageSize
    PageHelper.startPage(page,pageSize);
    //2.获取查询结果
    List<Emp> empList = empMapper.list(name,gender,begin,end);
    Page<Emp> p = (Page<Emp>) empList;
    return new PageBean(p.getTotal(),p.getResult());
}

    @Override
    public void delete(List<Integer> ids) {
    empMapper.delete(ids);

    }

    @Override
    public void save(Emp emp) {
    emp.setCreateTime(LocalDateTime.now());
    emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getById(Integer id) {

        return  empMapper.getByID(id);
    }

    @Override
    public void update(Emp emp) {
    emp.setUpdateTime(LocalDateTime.now());//forget everytime
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {

        return empMapper.getByUsernameAndPassword(emp);
    }


}
